﻿using System;
using System.Collections.Generic;
using RentalSystem.Data.EF.Core;

namespace RentalSystem.Data.EF.Dao
{
    public class EFCommentsDao : ICommentsDao
    {
        #region Queries

        private static string GetByGuidQuery;

        #endregion

        private EFManager<Comments> manager;

        public EFCommentsDao(RentalDatabaseEntities repository)
        {
            GetByGuidQuery = "SELECT VALUE c FROM Comments AS c WHERE c.CommentGuid = @Guid;";

            this.manager = new EFManager<Comments>(repository);
        }

        #region IDao1Key

        public Comments Add(Comments entity)
        {
            manager.Database.AddToComments(entity);
            manager.Save();
            return entity;
        }

        public Comments Get(string guid)
        {
            QueryParam[] parameters = new QueryParam[]
                {
                    new QueryParam("@Guid", guid)
                };

            var comments = manager.SQLQueryToEntity(GetByGuidQuery, parameters);

            foreach (Comments comment in comments)
            {
                return comment;
            }

            return null;
        }

        public void Delete(string guid)
        {
            manager.Database.Comments.DeleteObject(Get(guid));
            manager.Save();
        }

        public void Delete(Comments entity)
        {
            Delete(entity.CommentGuid);
        }

        public void Update(Comments entity, uint fields)
        {
            throw new NotImplementedException();
        }

        public List<Comments> List()
        {
            throw new NotImplementedException();
        }
        
        #endregion
    }
}
